home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’91 / DAL Files / DALtool 4⁄19 (System 6.x) / DalDialog.c < prev    next >
Text File  |  1991-04-18  |  2KB  |  118 lines

  1.  
  2. #include "DalDemo.h"
  3.  
  4. extern char gPassword[],gUsername[], gNodename[];
  5.  
  6. /*** CreateSession ***/
  7. CreateSession()
  8. {
  9.     DialogPtr    logonDialog;
  10.     int dialogDone = FALSE;
  11.     int     itemHit;
  12.     int     itemType;
  13.     Rect     itemRect;
  14.     Handle    itemHandle, OKHandle;
  15.     demoPeek demoWind;
  16.     Boolean    doCreate;
  17.     
  18.     doCreate = FALSE;
  19.     logonDialog = GetNewDialog(LOGON_DIALOG,NIL,MOVE_TO_FRONT);
  20.     GetDItem(logonDialog, OK_BUTTON, &itemType, &OKHandle, &itemRect);
  21.     
  22.     ShowWindow(logonDialog);
  23.     SetPort(logonDialog);
  24.     DrawOKButton(logonDialog);
  25.     
  26.     while (!dialogDone)
  27.     {
  28.         GetDItem(logonDialog, LOGON_PSWD, &itemType, &itemHandle, &itemRect);
  29.         GetIText(itemHandle, &gPassword);
  30.         if (gPassword[0] != NIL)
  31.             HiliteControl(OKHandle, 0);
  32.         else
  33.             HiliteControl(OKHandle, 255);
  34.             
  35.         ModalDialog(SignonFilter,&itemHit);
  36.         switch (itemHit)
  37.         {
  38.             case OK_BUTTON:
  39.                 GetDItem(logonDialog, LOGON_NODE, &itemType, &itemHandle, &itemRect);
  40.                 GetIText(itemHandle, &gNodename);
  41.                 GetDItem(logonDialog, LOGON_NAME, &itemType, &itemHandle, &itemRect);
  42.                 GetIText(itemHandle, &gUsername);
  43.                 doCreate = TRUE;
  44.             case CANCEL_BUTTON:
  45.                 dialogDone = TRUE;
  46.                 HideWindow(logonDialog);
  47.                 break;
  48.         }
  49.     }
  50.     if (doCreate)
  51.     {
  52.         CreateWindow();
  53.         demoWind = (demoPeek) FrontWindow();
  54.         DALOpenLink(demoWind,gNodename, gUsername, gPassword);
  55.     }
  56. }
  57.  
  58. /*** DrawOKButton ***/
  59. DrawOKButton(dp)
  60. DialogPtr dp;
  61. {
  62.     int        itemType;
  63.     Rect    itemRect;
  64.     Handle    item;
  65.     GrafPtr    oldPort;
  66.     
  67.     GetDItem(dp, OK_BUTTON, &itemType, &item, &itemRect);
  68.     GetPort(&oldPort);
  69.     SetPort( dp);
  70.     
  71.     PenSize(3,3);
  72.     InsetRect(&itemRect,-4,-4);
  73.     FrameRoundRect(&itemRect,16,16);
  74.     PenNormal();
  75.     
  76.     SetPort(oldPort);
  77. }
  78.  
  79.  
  80. /*** SignonFilter ***/
  81. pascal Boolean SignonFilter(dp, theEvent, itemHit)
  82. DialogPtr dp;
  83. EventRecord *theEvent;
  84. int *itemHit;
  85. {
  86.     Handle        item;
  87.     int            itemType;
  88.     Rect        itemRect;
  89.     char        theChar;
  90.     Str255        theStr;
  91.     int            selStart,selEnd;
  92.     int            flag = FALSE;
  93.     
  94.     GetDItem( dp, LOGON_PSWD, &itemType, &item, &itemRect);
  95.     GetIText( item, &theStr);
  96.     
  97.     if ((theEvent->what == keyDown) || (theEvent->what == autoKey))
  98.     {
  99.         theChar = (theEvent->message & charCodeMask);
  100.         if ((theChar == TE_CARRIAGE_RETURN) || (theChar == TE_ENTER_KEY))
  101.         {
  102.             if (theStr[0] != NIL)
  103.             {
  104.                 *itemHit = OK_BUTTON;
  105.                 GetDItem(dp, OK_BUTTON, &itemType, &item, &itemRect);
  106.                 HiliteControl(item,1);
  107.                 return(TRUE);
  108.             }
  109.             else
  110.             {
  111.                 *itemHit = LOGON_PSWD;
  112.                 return(TRUE);
  113.             }
  114.         }
  115.     }
  116.     return(FALSE);
  117. }
  118.